﻿using Furion;
using Furion.DatabaseAccessor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using UpperComputer.Base.Core;
using UpperComputer.Base.Core.Locators;
using YFurion.Security;

namespace UpperComputer.Base.EntityFramework.Core;

public class UpperComputerBaseEntityFrameworkCoreServiceComponent : IServiceComponent
{
    public void Load(IServiceCollection services, ComponentContext componentContext)
    {
        IConfiguration configuration = App.Configuration;
        services.AddDatabaseAccessor(options =>
        {
            string mcs = Des3.Decrypt(configuration.GetConnectionString("BaseMasterConnectionString"), UpperComputerBaseCoreConst.HashPrefix);
            string scs = Des3.Decrypt(configuration.GetConnectionString("BaseSlaveConnectionString"), UpperComputerBaseCoreConst.HashPrefix);
            services.AddDbPool<BaseMasterDbContext, BaseMasterDbContextLocator>(DbProvider.SqlServer, connectionMetadata: mcs);
            services.AddDbPool<BaseSlaveDbContext, BaseSlaveDbContextLocator>(DbProvider.SqlServer, connectionMetadata: scs);
        }, "UpperComputer.Base.Database.Migrations");
    }
}
